package com.tianpengtech.common.util;

import org.apache.commons.mail.EmailException;
import org.apache.commons.mail.HtmlEmail;

import com.jfinal.kit.Kv;

public class SendmailUtil {

	private static final String HOST_NAME="smtp.163.com";
	private static final String USER="m13641489216@163.com";
	private static final String PASS="HCS89731";
	
	public static void sendHtmlEmail(String subject,String content,String to) {
		try {
			HtmlEmail email = new HtmlEmail();
			email.setCharset("UTF-8");
			email.setHostName(HOST_NAME);
			email.setSSLOnConnect(true);
			email.addTo(to);  
			email.setAuthentication(USER,PASS);  
			email.setFrom(USER);
			email.setSubject(subject);
			email.setHtmlMsg(content);
			email.send();
		} catch (EmailException e) {
			e.printStackTrace();
		}
	}
	
	/*
	 *  给指定的多人发邮件，由于邮件信息数量不是特别多，所以采用当前方式
	 */
	public static void sendHtmlEmail(String subject,String content,String[] to){
		for (String each : to) {
			sendHtmlEmail(subject,content,each);
		}
	}
}
